using System.Drawing;
using GTA;
using NativeUI;

namespace CustomPeds.Menus;

public class DressingRoomAdvancedMenu : Script
{
	public static UIMenu menu = new UIMenu("", TextSetting.dra_Menu, new Point(0, -107));

	private static bool isMenuInitialized;

	public DressingRoomAdvancedMenu()
	{
		if (!isMenuInitialized)
		{
			Main.pool.Add(menu);
			menu.OnMenuClose += OnMenuClose;
			menu.OnItemSelect += OnItemSelect;
			isMenuInitialized = true;
		}
	}

	public static void InitAdvancedMenu()
	{
		menu.Clear();
		menu.SetBannerType(new UIResRectangle());
		menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_HeadBlend, TextSetting.dr_MenuItem_AdvancedSettings_dct));
		menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_FaceFeature, TextSetting.dr_MenuItem_AdvancedSettings_dct));
		menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_HeadOverlay, TextSetting.dr_MenuItem_AdvancedSettings_dct));
		menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_SpeechSettings, TextSetting.dra_MenuItem_SpeechSettings_dct));
		menu.BindMenuToItem(HeadBlendSubMenu.menu, menu.MenuItems[0]);
		menu.BindMenuToItem(FaceFeatureSubMenu.menu, menu.MenuItems[1]);
		menu.BindMenuToItem(HeadOverlayMenu.menu, menu.MenuItems[2]);
		menu.BindMenuToItem(SpeechMenu.menu, menu.MenuItems[3]);
		menu.RefreshIndex();
		CheckCanUseMenuItem();
	}

	public static void CheckCanUseMenuItem()
	{
		bool flag = false;
		if (DressingScript.Dressing == Main.Member.P2)
		{
			if (Main.P2.skin.Head_Blend.action)
			{
				flag = true;
			}
		}
		else if (Main.P1.skin.Head_Blend.action)
		{
			flag = true;
		}
		for (int i = 1; i < 3; i++)
		{
			menu.MenuItems[i].Enabled = false;
		}
		for (int j = 1; j < 3; j++)
		{
			if (flag)
			{
				menu.MenuItems[j].Enabled = true;
			}
		}
	}

	private void OnItemSelect(UIMenu sender, UIMenuItem item, int index)
	{
		if (index == 0)
		{
			HeadBlendSubMenu.InitHeadBlendSubMenu();
		}
		if (index == 1)
		{
			FaceFeatureSubMenu.InitFaceFeatureSubMenu();
		}
		if (index == 2)
		{
			HeadOverlayMenu.InitHeadOverlayMenu();
		}
		if (index == 3)
		{
			SpeechMenu.InitSpeakMenu();
		}
	}

	private void OnIndexChange(UIMenu sender, int index)
	{
	}

	private void OnMenuClose(UIMenu sender)
	{
		menu.Visible = false;
		menu.RefreshIndex();
	}
}
